class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int ma = 1e9;
        int j = 0;
        int ans = 0;
        int n = nums.size();
        for (int i = 0; i < n; i++) {
            ans += nums[i];
            while (ans >= target) {
                ma = min(ma, i - j + 1);
                ans -= nums[j++];
            }
        }
        if (ma == 1e9)return 0;
        else return ma;
    }
};